package com.ilock.service;
import java.util.List;

import com.ilock.bean.Ilockpicture;
import com.ilock.bean.IlockpictureDAO;

public class PictureServiceImpl implements IPictureService{
	
	private IlockpictureDAO IlockpictureDAO;

	public IlockpictureDAO getIlockpictureDAO() {
		return IlockpictureDAO;
	}

	public void setIlockpictureDAO(IlockpictureDAO ilockpictureDAO) {
		IlockpictureDAO = ilockpictureDAO;
	}

	@Override
	public List getPictureUrlByLockId(int lockID) {
		// TODO Auto-generated method stub
		return IlockpictureDAO.findByIlockInfoNumber(lockID);
	}

	@Override
	public void addPicture(int lockID,String pictureurl) {
		// TODO Auto-generated method stub
		Ilockpicture picture = new Ilockpicture();
		picture.setIlockInfoNumber(lockID);
		picture.setIpictureUrl(pictureurl);
		IlockpictureDAO.merge(picture);
	}

	@Override
	public void updatePicture(Ilockpicture ipicture) {
		// TODO Auto-generated method stub
		IlockpictureDAO.merge(ipicture);
	}

	@Override
	public void deletePictureById(int pictureID) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void deletePictureByLockId(int lockID) {
		// TODO Auto-generated method stub
		List pictureList = IlockpictureDAO.findByIlockInfoNumber(lockID);
		if(!pictureList.isEmpty()){
			for(int i=0;i<pictureList.size();i++){
				Ilockpicture temppicture = (Ilockpicture) pictureList.get(i);
				IlockpictureDAO.delete(temppicture);
			}
		}
	}
	
	

}
